package com.a_b.back_end.base;

import com.fasterxml.jackson.annotation.JsonInclude;

import java.io.Serializable;

/**
 * @author agrinJPG
 * @date 2021/5/3 21:27
 * @Description 前端返回对象，Controller的直接返回对象都是Result
 */
public class Result implements Serializable {
    private static final long serialVersionUID = 232908545350224988L;
    // 成功标志
    private boolean success = true;
    // 状态码
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Integer status;
    // 编码，可用于前端处理多语言，不需要则不用返回编码
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String encode;
    // 相关消息
    private String msg;
    // 相关数据
    private Object data;

    public Result(){}
    public Result(boolean success) {
        this.success = success;
    }

    public Result(boolean success, Integer status) {
        this.success = success;
        this.status = status;
    }

    public Result(boolean success, String encode, String msg){
        this(success);
        this.encode = encode;
        this.msg = msg;
    }

    public Result(boolean success, Integer status, String encode, String msg) {
        this.success = success;
        this.status = status;
        this.encode = encode;
        this.msg = msg;
    }

    public Result(boolean success, String encode, String msg, Object data){
        this(success);
        this.encode = encode;
        this.msg = msg;
        this.data = data;
    }

    public boolean isSuccess() {
        return success;
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public Integer getStatus() {
        return status;
    }

    public String getEncode() {
        return encode;
    }

    public String getMsg() {
        return msg;
    }

    public Object getData() {
        return data;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public void setEncode(String encode) {
        this.encode = encode;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
